<!doctype html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>SayOrder</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"
        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"
        integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
        crossorigin="anonymous"></script>
    <!-- common.js -->
    <script type="text/javascript" src="/js/common.js"></script>
    <script>

        $(document).ready(function () {
            // 在这里编写需要在页面加载完毕后执行的代码
            $("#success").hide();
            $("#fail").hide();
        });
        function hide(node) {
            setTimeout(() => {
                $("#" + node).fadeOut(1000);
            }, 4000);
        }
        function myLogin() {
            let account = $("#account").val();
            let passWord = $("#passWord").val();
            if (account !== "" && passWord !== "") {
                var params = {
                    "account": account,
                    "pass_word": passWord
                };
                $.ajax({
                    type: "POST",
                    url: "/admin/login",
                    data: JSON.stringify(params),
                    contentType: "application/json",
                    success: function (response, status, xhr) {
                        if (response.error === 0) {//
                            switch (response.role) {
                                case 1://管理员
                                    window.globalRoleId = 1;
                                    window.location.href = "/api/to_admin";
                                    break;
                                case 2://标注员
                                    window.globalRoleId = 2;
                                    window.location.href = "/api/to_worker";
                                    break;
                            }
                        } else {//异常返回
                            $("#fail").text(data.errorMessage + "！");
                            $("#fail").fadeIn(1000, hide("fail"));
                        }
                    }
                });
            } else {
                alert("登录信息没有填写完整");
            }
        }
        function mySubmit() {
            let account = $("#account").val();
            let passWord = $("#passWord").val();
            let name = $("#name").val();
            if (account !== "" && passWord !== "" && name !== "") {
                var params = {
                    "account": account,
                    "pass_word": passWord,
                    "name": name,
                };
                $.ajax({
                    type: "POST",
                    url: "/admin/register",
                    data: JSON.stringify(params),
                    contentType: "application/json",
                    success: function (data) {
                        if (data.error === 0) {//正常返回
                            $("#success").fadeIn(1000, hide("success"));
                        } else {//异常返回
                            $("#fail").text(data.errorMessage + "！");
                            $("#fail").fadeIn(1000, hide("fail"));
                        }
                    }
                });
            } else {
                alert("注册信息没有填写完整");
            }
        }
    </script>
</head>

<body style="overflow-x: hidden;">
    <div class="jumbotron" style="padding-left: 5%;">
        <div class="container">
            <h1>SayOrder</h1>
            <p>SayOrder——基于easyAI开源引擎的智能客服管理系统</p>
        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2" style="border:1px solid rgb(92, 91, 91);border-radius: 15px;padding: 1%;">
                <div class="alert alert-success" role="alert" id="success">账号申请成功，请等待超管审核通过后再次登录！</div>
                <div class="alert alert-danger" role="alert" id="fail">账号申请失败！</div>
                <h3 for="basic-url" style="text-align: center;">注册/登录</h3>
                <div class="input-group input-group-lg" style="margin-top: 20px;">
                    <span class="input-group-addon" id="basic-addon1">账号:</span>
                    <input type="text" class="form-control" id="account" aria-describedby="basic-addon1">
                </div>
                <div class="input-group input-group-lg" style="margin-top: 20px;">
                    <span class="input-group-addon" id="basic-addon1">密码:</span>
                    <input type="password" class="form-control" id="passWord" aria-describedby="basic-addon2">
                </div>
                <div class="input-group input-group-lg" style="margin-top: 20px;">
                    <span class="input-group-addon" id="basic-addon1">姓名:</span>
                    <input type="text" class="form-control" id="name" aria-describedby="basic-addon2">
                </div>
                <div class="btn-group btn-group-justified" role="group" style="margin-top: 20px;border-radius: 5px;">
                    <div class="btn-group" role="group">
                        <button type="button" class="btn btn-primary" onclick="myLogin()">登录</button>
                    </div>
                    <div class="btn-group" role="group">
                        <button type="button" class="btn btn-default" onclick="mySubmit()">注册</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>